Changing lines like this: "extract( $dbw->tableNames( 'page', 'archive' ) );" to...
authorNick Jenkins <nickj@users.mediawiki.org>
Mon, 27 Nov 2006 08:36:57 +0000 (08:36 +0000)
committerNick Jenkins <nickj@users.mediawiki.org>
Mon, 27 Nov 2006 08:36:57 +0000 (08:36 +0000)
Three reasons for this:
1) It's better for analysis tools [which want explicit variable declaration]
2) It's easier for a human to read, as it's completely explicit where the variables came from [which is something you don't get with extract() ]
3) It makes it easier to find everywhere where a variable is used with search/grep [which you can't currently do with $tbl_page variables from things like: "extract($db->tableNames( 'page', 'revision'), EXTR_PREFIX_ALL, 'tbl');"].

Otherwise, from a functionality/efficiency perspective the two forms should be identical.

By doing this have been able run static analysis over the usages of these variables, thus eliminating 5 unneeded table names from calls, plus removing 3 unused calls entirely, and it just feels subjectively slightly nicer to me.

33 files changed:
includes/Block.php
includes/Database.php
includes/Image.php
includes/SiteStats.php
includes/Skin.php
includes/SkinTemplate.php
includes/SpecialBrokenRedirects.php
includes/SpecialContributions.php
includes/SpecialDeadendpages.php
includes/SpecialDoubleRedirects.php
includes/SpecialLonelypages.php
includes/SpecialMostcategories.php
includes/SpecialMostimages.php
includes/SpecialMostlinked.php
includes/SpecialMostlinkedcategories.php
includes/SpecialMostrevisions.php
includes/SpecialNewpages.php
includes/SpecialRecentchanges.php
includes/SpecialRecentchangeslinked.php
includes/SpecialStatistics.php
includes/SpecialUncategorizedimages.php
includes/SpecialUncategorizedpages.php
includes/SpecialUndelete.php
includes/SpecialUnusedcategories.php
includes/SpecialUnusedimages.php
includes/SpecialUnusedtemplates.php
includes/SpecialUnwatchedpages.php
includes/SpecialWantedcategories.php
includes/SpecialWatchlist.php
includes/SpecialWhatlinkshere.php
includes/UserMailer.php
includes/api/ApiQueryLogEvents.php
includes/api/ApiQueryUserContributions.php

index 97b1f43..15b3972 100644 (file)
@@ -308,7 +308,7 @@ class Block
 
                $now = wfTimestampNow();
 
-               extract( $db->tableNames( 'ipblocks', 'user' ) );
+               list( $ipblocks, $user ) = $db->tableNamesN( 'ipblocks', 'user' );
 
                $sql = "SELECT $ipblocks.*,user_name FROM $ipblocks,$user " .
                        "WHERE user_id=ipb_by $cond ORDER BY ipb_timestamp DESC $options";
index d8f7757..e707546 100644 (file)
@@ -1383,7 +1383,7 @@ class Database {
         * $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user
         *         WHERE wl_user=user_id AND wl_user=$nameWithQuotes";
         */
-       function tableNames() {
+       public function tableNames() {
                $inArray = func_get_args();
                $retVal = array();
                foreach ( $inArray as $name ) {
@@ -1391,6 +1391,24 @@ class Database {
                }
                return $retVal;
        }
+       
+       /**
+        * @desc: Fetch a number of table names into an zero-indexed numerical array
+        * This is handy when you need to construct SQL for joins
+        *
+        * Example:
+        * list( $user, $watchlist ) = $dbr->tableNames('user','watchlist');
+        * $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user
+        *         WHERE wl_user=user_id AND wl_user=$nameWithQuotes";
+        */
+       public function tableNamesN() {
+               $inArray = func_get_args();
+               $retVal = array();
+               foreach ( $inArray as $name ) {
+                       $retVal[] = $this->tableName( $name );
+               }
+               return $retVal;
+       }
 
        /**
         * @private
index c03466b..5170536 100644 (file)
@@ -1702,7 +1702,7 @@ class Image
                }
                $linkCache =& LinkCache::singleton();
 
-               extract( $db->tableNames( 'page', 'imagelinks' ) );
+               list( $page, $imagelinks ) = $db->tableNamesN( 'page', 'imagelinks' );
                $encName = $db->addQuotes( $this->name );
                $sql = "SELECT page_namespace,page_title,page_id FROM $page,$imagelinks WHERE page_id=il_from AND il_to=$encName $options";
                $res = $db->query( $sql, __METHOD__ );
index 4480ab5..50a2204 100644 (file)
@@ -127,7 +127,7 @@ class SiteStatsUpdate {
                        # Update schema if required
                        if ( $row->ss_total_pages == -1 && !$this->mViews ) {
                                $dbr =& wfGetDB( DB_SLAVE, array( 'SpecialStatistics', 'vslow') );
-                               extract( $dbr->tableNames( 'page', 'user' ) );
+                               list( $page, $user ) = $dbr->tableNamesN( 'page', 'user' );
 
                                $sql = "SELECT COUNT(page_namespace) AS total FROM $page";
                                $res = $dbr->query( $sql, $fname );
index da0f507..43c7695 100644 (file)
@@ -1034,7 +1034,7 @@ END;
 
                if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
                        $dbr =& wfGetDB( DB_SLAVE );
-                       extract( $dbr->tableNames( 'watchlist' ) );
+                       $watchlist = $dbr->tableName( 'watchlist' );
                        $sql = "SELECT COUNT(*) AS n FROM $watchlist
                                WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
                                "' AND  wl_namespace=" . $wgTitle->getNamespace() ;
index 95bd876..f804114 100644 (file)
@@ -54,6 +54,7 @@ class MediaWiki_I18N {
 
                $value = wfMsg( $value );
                // interpolate variables
+               $m = array();
                while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
                        list($src, $var) = $m;
                        wfSuppressWarnings();
@@ -344,7 +345,7 @@ class SkinTemplate extends Skin {
 
                        if ($wgPageShowWatchingUsers) {
                                $dbr =& wfGetDB( DB_SLAVE );
-                               extract( $dbr->tableNames( 'watchlist' ) );
+                               $watchlist = $dbr->tableName( 'watchlist' );
                                $sql = "SELECT COUNT(*) AS n FROM $watchlist
                                        WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
                                        "' AND  wl_namespace=" . $this->mTitle->getNamespace() ;
index 653e13e..5093565 100644 (file)
@@ -27,7 +27,7 @@ class BrokenRedirectsPage extends PageQueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'page', 'pagelinks' ) );
+               list( $page, $pagelinks ) = $dbr->tableNamesN( 'page', 'pagelinks' );
 
                $sql = "SELECT 'BrokenRedirects'  AS type,
                                p1.page_namespace AS namespace,
index 5d058e9..f9fe14e 100644 (file)
@@ -31,7 +31,7 @@ class ContribsFinder {
                list( $index, $usercond ) = $this->getUserCond();
                $nscond = $this->getNamespaceCond();
                $use_index = $this->dbr->useIndexClause( $index );
-               extract( $this->dbr->tableNames( 'revision', 'page' ) );
+               list( $revision, $page) = $this->dbr->tableNamesN( 'revision', 'page' );
                $sql =  "SELECT rev_timestamp " .
                        " FROM $page,$revision $use_index " .
                        " WHERE rev_page=page_id AND $usercond $nscond" .
@@ -82,7 +82,7 @@ class ContribsFinder {
                $nscond = $this->getNamespaceCond();
 
                $use_index = $this->dbr->useIndexClause( $index );
-               extract( $this->dbr->tableNames( 'page', 'revision' ) );
+               list( $page, $revision ) = $this->dbr->tableNamesN( 'page', 'revision' );
 
                $sql =  "SELECT rev_timestamp FROM $page, $revision $use_index " .
                        "WHERE page_id = rev_page AND rev_timestamp > '" . $this->offset . "' AND " .
@@ -106,7 +106,7 @@ class ContribsFinder {
        function getFirstOffsetForPaging() {
                list( $index, $usercond ) = $this->getUserCond();
                $use_index = $this->dbr->useIndexClause( $index );
-               extract( $this->dbr->tableNames( 'page', 'revision' ) );
+               list( $page, $revision ) = $this->dbr->tableNamesN( 'page', 'revision' );
                $nscond = $this->getNamespaceCond();
                $sql =  "SELECT rev_timestamp FROM $page, $revision $use_index " .
                        "WHERE page_id = rev_page AND " .
@@ -128,9 +128,9 @@ class ContribsFinder {
        }
 
        /* private */ function makeSql() {
-               $userCond = $condition = $index = $offsetQuery = '';
+               $offsetQuery = '';
 
-               extract( $this->dbr->tableNames( 'page', 'revision' ) );
+               list( $page, $revision ) = $this->dbr->tableNamesN( 'page', 'revision' );
                list( $index, $userCond ) = $this->getUserCond();
 
                if ( $this->offset )
index b319a17..4ffe5e0 100644 (file)
@@ -43,7 +43,7 @@ class DeadendPagesPage extends PageQueryPage {
         */
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'page', 'pagelinks' ) );
+               list( $page, $pagelinks ) = $dbr->tableNamesN( 'page', 'pagelinks' );
                return "SELECT 'Deadendpages' as type, page_namespace AS namespace, page_title as title, page_title AS value " .
        "FROM $page LEFT JOIN $pagelinks ON page_id = pl_from " .
        "WHERE pl_from IS NULL " .
index fe42b00..cf1153e 100644 (file)
@@ -26,7 +26,7 @@ class DoubleRedirectsPage extends PageQueryPage {
 
        function getSQLText( &$dbr, $namespace = null, $title = null ) {
                
-               extract( $dbr->tableNames( 'page', 'pagelinks' ) );
+               list( $page, $pagelinks ) = $dbr->tableNamesN( 'page', 'pagelinks' );
 
                $limitToTitle = !( $namespace === null && $title === null );
                $sql = $limitToTitle ? "SELECT" : "SELECT 'DoubleRedirects' as type," ;
index 1502292..8770a9e 100644 (file)
@@ -30,7 +30,7 @@ class LonelyPagesPage extends PageQueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'page', 'pagelinks' ) );
+               list( $page, $pagelinks ) = $dbr->tableNamesN( 'page', 'pagelinks' );
 
                return
                  "SELECT 'Lonelypages'  AS type,
index c0d662c..06002af 100644 (file)
@@ -20,7 +20,7 @@ class MostcategoriesPage extends QueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'categorylinks', 'page' ) );
+               list( $categorylinks, $page) = $dbr->tableNamesN( 'categorylinks', 'page' );
                return
                        "
                        SELECT
index 09f7108..17c07c7 100644 (file)
@@ -20,7 +20,7 @@ class MostimagesPage extends QueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'imagelinks' ) );
+               $imagelinks = $dbr->tableName( 'imagelinks' );
                return
                        "
                        SELECT
index 6f5f30d..4df53ae 100644 (file)
@@ -28,7 +28,7 @@ class MostlinkedPage extends QueryPage {
         */
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'pagelinks', 'page' ) );
+               list( $pagelinks, $page ) = $dbr->tableNamesN( 'pagelinks', 'page' );
                return
                        "SELECT 'Mostlinked' AS type,
                                pl_namespace AS namespace,
index 5942b3f..e1f8484 100644 (file)
@@ -22,7 +22,7 @@ class MostlinkedCategoriesPage extends QueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'categorylinks', 'page' ) );
+               $categorylinks = $dbr->tableName( 'categorylinks' );
                $name = $dbr->addQuotes( $this->getName() );
                return
                        "
index 676923a..1e3334e 100644 (file)
@@ -22,7 +22,7 @@ class MostrevisionsPage extends QueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'revision', 'page' ) );
+               list( $revision, $page ) = $dbr->tableNamesN( 'revision', 'page' );
                return
                        "
                        SELECT
index a9a028b..987afa3 100644 (file)
@@ -42,7 +42,7 @@ class NewPagesPage extends QueryPage {
                global $wgUser, $wgUseRCPatrol;
                $usepatrol = ( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) ) ? 1 : 0;
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'recentchanges', 'page', 'text' ) );
+               list( $recentchanges, $page ) = $dbr->tableNamesN( 'recentchanges', 'page' );
 
                $uwhere = $this->makeUserWhere( $dbr );
 
@@ -172,6 +172,7 @@ function wfSpecialNewpages($par, $specialPage) {
                        if ( is_numeric( $bit ) )
                                $limit = $bit;
 
+                       $m = array();
                        if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
                                $limit = intval($m[1]);
                        if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
index b7ed130..267d762 100644 (file)
@@ -108,7 +108,7 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
 
        # Database connection and caching
        $dbr =& wfGetDB( DB_SLAVE );
-       extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
+       list( $recentchanges, $watchlist ) = $dbr->tableNamesN( 'recentchanges', 'watchlist' );
 
 
        $cutoff_unixtime = time() - ( $days * 86400 );
index 8dcb1dd..c1c0240 100644 (file)
@@ -67,7 +67,8 @@ function wfSpecialRecentchangeslinked( $par = NULL ) {
                $cmq = 'AND rc_minor=0';
        } else { $cmq = ''; }
 
-       extract( $dbr->tableNames( 'recentchanges', 'categorylinks', 'pagelinks', 'revision', 'page' , "watchlist" ) );
+       list($recentchanges, $categorylinks, $pagelinks, $watchlist) = 
+           $dbr->tableNamesN( 'recentchanges', 'categorylinks', 'pagelinks', "watchlist" );
 
        $uid = $wgUser->getID();
 
index 66b1424..a5a0fc3 100644 (file)
@@ -15,7 +15,6 @@ function wfSpecialStatistics() {
        $action = $wgRequest->getVal( 'action' );
 
        $dbr =& wfGetDB( DB_SLAVE );
-       extract( $dbr->tableNames( 'site_stats', 'user', 'user_groups' ) );
 
        $views = SiteStats::views();
        $edits = SiteStats::edits();
@@ -59,6 +58,7 @@ function wfSpecialStatistics() {
 
                global $wgDisableCounters, $wgMiserMode, $wgUser, $wgLang, $wgContLang;
                if( !$wgDisableCounters && !$wgMiserMode ) {
+                       $page = $dbr->tableName( 'page' );
                        $sql = "SELECT page_namespace, page_title, page_counter FROM {$page} WHERE page_is_redirect = 0 AND page_counter > 0 ORDER BY page_counter DESC";
                        $sql = $dbr->limitResult($sql, 10, 0);
                        $res = $dbr->query( $sql, $fname );
index 3815697..1daba8e 100644 (file)
@@ -28,7 +28,7 @@ class UncategorizedImagesPage extends QueryPage {
        
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'page', 'categorylinks' ) );
+               list( $page, $categorylinks ) = $dbr->tableNamesN( 'page', 'categorylinks' );
                $ns = NS_IMAGE;
 
                return "SELECT 'Uncategorizedimages' AS type, page_namespace AS namespace,
index 0ecc5d0..dbf23a6 100644 (file)
@@ -28,7 +28,7 @@ class UncategorizedPagesPage extends PageQueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'page', 'categorylinks' ) );
+               list( $page, $categorylinks ) = $dbr->tableNamesN( 'page', 'categorylinks' );
                $name = $dbr->addQuotes( $this->getName() );
 
                return
index 421063e..f3bdb6a 100644 (file)
@@ -278,12 +278,12 @@ class PageArchive {
         * @return int number of revisions restored
         */
        private function undeleteRevisions( $timestamps ) {
-               global $wgParser, $wgDBtype;
+               global $wgDBtype;
 
                $restoreAll = empty( $timestamps );
                
                $dbw =& wfGetDB( DB_MASTER );
-               extract( $dbw->tableNames( 'page', 'archive' ) );
+               $page = $dbw->tableName( 'archive' );
 
                # Does this page already exist? We'll have to update it...
                $article = new Article( $this->title );
@@ -453,6 +453,7 @@ class UndeleteForm {
                        $timestamps = array();
                        $this->mFileVersions = array();
                        foreach( $_REQUEST as $key => $val ) {
+                               $matches = array();
                                if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
                                        array_push( $timestamps, $matches[1] );
                                }
index 270180e..6520513 100644 (file)
@@ -23,7 +23,7 @@ class UnusedCategoriesPage extends QueryPage {
        function getSQL() {
                $NScat = NS_CATEGORY;
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'categorylinks','page' ));
+               list( $categorylinks, $page ) = $dbr->tableNamesN( 'categorylinks', 'page' );
                return "SELECT 'Unusedcategories' as type,
                                {$NScat} as namespace, page_title as title, 1 as value
                                FROM $page
index 32a6f95..75d702c 100644 (file)
@@ -25,7 +25,7 @@ class UnusedimagesPage extends QueryPage {
                $dbr =& wfGetDB( DB_SLAVE );
 
                if ( $wgCountCategorizedImagesAsUsed ) {
-                       extract( $dbr->tableNames( 'page', 'image', 'imagelinks', 'categorylinks' ) );
+                       list( $page, $image, $imagelinks, $categorylinks ) = $dbr->tableNamesN( 'page', 'image', 'imagelinks', 'categorylinks' );
 
                        return 'SELECT img_name as title, img_user, img_user_text, img_timestamp as value, img_description
                                        FROM ((('.$page.' AS I LEFT JOIN '.$categorylinks.' AS L ON I.page_id = L.cl_from)
@@ -33,7 +33,7 @@ class UnusedimagesPage extends QueryPage {
                                                INNER JOIN '.$image.' AS G ON I.page_title = G.img_name)
                                        WHERE I.page_namespace = '.NS_IMAGE.' AND L.cl_from IS NULL AND P.il_to IS NULL';
                } else {
-                       extract( $dbr->tableNames( 'image','imagelinks' ) );
+                       list( $image, $imagelinks ) = $dbr->tableNamesN( 'image','imagelinks' );
 
                        return 'SELECT img_name as title, img_user, img_user_text, img_timestamp as value, img_description' .
                        ' FROM '.$image.' LEFT JOIN '.$imagelinks.' ON img_name=il_to WHERE il_to IS NULL ';
index d232f02..2af9abc 100644 (file)
@@ -23,7 +23,7 @@ class UnusedtemplatesPage extends QueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'page', 'templatelinks' ) );
+               list( $page, $templatelinks) = $dbr->tableNamesN( 'page', 'templatelinks' );
                $sql = "SELECT 'Unusedtemplates' AS type, page_title AS title,
                        page_namespace AS namespace, 0 AS value
                        FROM $page
index 66e5c09..f9dff72 100644 (file)
@@ -22,7 +22,7 @@ class UnwatchedpagesPage extends QueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'page', 'watchlist' ) );
+               list( $page, $watchlist ) = $dbr->tableNamesN( 'page', 'watchlist' );
                $mwns = NS_MEDIAWIKI;
                return
                        "
index 97bb0a2..05ee7ec 100644 (file)
@@ -22,7 +22,7 @@ class WantedCategoriesPage extends QueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'categorylinks', 'page' ) );
+               list( $categorylinks, $page ) = $dbr->tableNamesN( 'categorylinks', 'page' );
                $name = $dbr->addQuotes( $this->getName() );
                return
                        "
index 760bb8d..0441f55 100644 (file)
@@ -113,7 +113,7 @@ function wfSpecialWatchlist( $par ) {
        }
 
        $dbr =& wfGetDB( DB_SLAVE );
-       extract( $dbr->tableNames( 'page', 'revision', 'watchlist', 'recentchanges' ) );
+       list( $page, $watchlist, $recentchanges ) = $dbr->tableNamesN( 'page', 'watchlist', 'recentchanges' );
 
        $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
        $res = $dbr->query( $sql, $fname );
index 438f52e..bed783f 100644 (file)
@@ -76,8 +76,6 @@ class WhatLinksHerePage {
 
                $dbr =& wfGetDB( DB_READ );
 
-               extract( $dbr->tableNames( 'pagelinks', 'templatelinks', 'page' ) );
-
                // Some extra validation
                $from = intval( $from );
                if ( !$from && $dir == 'prev' ) {
index 8953d7a..a982439 100644 (file)
@@ -248,7 +248,6 @@ class EmailNotification {
                        }
                        if( $userCondition ) {
                                $dbr =& wfGetDB( DB_MASTER );
-                               extract( $dbr->tableNames( 'watchlist' ) );
 
                                $res = $dbr->select( 'watchlist', array( 'wl_user' ),
                                        array(
index 4c894bc..f6d55bf 100644 (file)
@@ -41,7 +41,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
 
                $db = & $this->getDB();
 
-               extract($db->tableNames('logging', 'page', 'user'), EXTR_PREFIX_ALL, 'tbl');
+               list($tbl_logging, $tbl_page, $tbl_user) = $db->tableNamesN('logging', 'page', 'user');
 
                $this->addOption('STRAIGHT_JOIN');
                $this->addTables("$tbl_logging LEFT OUTER JOIN $tbl_page ON " .
index 65e5737..e0bb692 100644 (file)
@@ -54,8 +54,8 @@ class ApiQueryContributions extends ApiQueryBase {
                if (!$userid)
                        $this->dieUsage("User name $user not found", 'param_user');
 
-               //Extract the table names, in case we have a prefix
-               extract($db->tableNames( 'page', 'revision'), EXTR_PREFIX_ALL, 'tbl');
+               //Get the table names
+               list ($tbl_page, $tbl_revision) = $db->tableNamesN('page', 'revision');
 
                //We're after the revision table, and the corresponding page row for
                //anything we retrieve.